#include <QFile>
#include <QTextStream>
#include <QDebug>
#include "settings.h"
#include "ui_settings.h"
#include "about.h"

Settings::Settings(QWidget *parent) :
    QFrame(parent),
    ui(new Ui::Settings)
{
    ui->setupUi(this);

    setFirmwareVersion("n/a");
}

Settings::~Settings()
{
    delete ui;
}

void Settings::setFirmwareVersion(QString version)
{
    ui->textAbout->setHtml(QString::fromUtf8("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\""
                                             " \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
                                             "<html><head><meta name=\"qrichtext\" content=\"1\""
                                             " /><style type=\"text/css\">\n"
                                             "p, li { white-space: pre-wrap; }\n"
                                             "</style></head><body>\n"
                                             "<p style=\" margin-top:0px; margin-bottom:0px; "
                                             "margin-left:0px; margin-right:0px; -qt-block-indent:"
                                             "0; text-indent:0px;\"><span style=\" font-size:"
                                             "normal;\">")
                           + mClientVersionString
                           + QString::fromUtf8("<br />AR.Drone firmware version: ")
                           + version + QString::fromUtf8("<br /><br />")
                           + mAboutString + QString::fromUtf8("<br /><br />")
                           + mNokiaString + QString::fromUtf8("<br />")
                           + mParrotString + QString::fromUtf8("</span></p></body></html>"));
}

void Settings::saveSettings()
{
    qDebug() << "saveSettings()";
/*
    QFile file("settings.txt");
    file.open(QIODevice::WriteOnly | QIODevice::Text);
    QTextStream out(&file);

    out << "option1:true";

    file.close();
*/
    qDebug() << "saveSettings() done";
}

void Settings::loadSettings()
{
/*
    QFile file("settings.txt");
    bool fileExist = file.open(QIODevice::ReadOnly | QIODevice::Text);
    if (fileExist) {
        QTextStream in(&file);
        QString line;
        while ((line = in.readLine()) != NULL)
        {
            QStringList option;
            option = line.split(":");

            if (option[OPTION_NAME] == "option1") {
                if (option[OPTION_VALUE] == "true") {

                } else {

                }
            }
        }
        file.close();
    } else {
        saveSettings();
    }
*/
}

void Settings::on_buttonBack_clicked()
{
    emit back();
}
